<?php
namespace Common\Service;

class SmsService
{
    /**
     * 给手机发送短信
     * @param  string $phone [description]
     * @param  [type] $text  [description]
     * @return [type]        [description]
     */
    public function send($phone, $text)
    {
        $conf = C('SMS.' . C('SMS_TYPE'));

        Vendor('Sms.' . C('SMS_TYPE'));
        $sms = new \Sms($conf['key'], '255');

        // 检查手机号码
        if (!is_phone($phone)) {
            return '手机号码错误';
        }

        // 发送验证码
        $data['apikey'] = $conf['key'];
        $data['text']   = $text;
        $data['mobile'] = $phone;
        $result         = $sms->send($data);

        // 数据返回
        if ($result['code'] == 0) {
            return $code;
        } else {
            return $result;
        }
    }
}
